package leetcode.ge100;

import leetcode.lt100.TreeNode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Solution_108 {


    public static void main(String[] args) {
        int[] nums = {-10, -3, 0, 5, 9};
        new Solution_108().sortedArrayToBST(nums);
    }


    public TreeNode sortedArrayToBST(int[] nums) {
        return sortedArrayToBST(nums, 0, nums.length);
    }

    private TreeNode sortedArrayToBST(int[] nums, int start, int end) {
        if (start == end) {
            return null;
        }
        int midIndex = (end + start) / 2;
        TreeNode treeNode = new TreeNode(nums[midIndex]);
        treeNode.right = sortedArrayToBST(nums, midIndex + 1, end);
        treeNode.left = sortedArrayToBST(nums, start, midIndex);
        return treeNode;
    }

}